package com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.aibkAnalysisDXT


import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.AnalysisInforIndexHelp.getChildListBean
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkDialog.ShowDialogTools
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperPerAnalysisInfor
import com.lancoo.znbkxx.teacher.utils.WebStyleUtils
import com.lancoo.znbkxx.teacher.widget.CustomTextViewToPicture
import kotlinx.android.synthetic.main.aibk_adapter_item_child_xzt.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_childask_dxt.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_itemanalysis.view.*
import java.util.ArrayList

class AnalysisAdapterChildDxt(
        val activity:AppCompatActivity,
        val paperPerAnalysisInfor: PaperPerAnalysisInfor,
        val index_A:Int,
        val index_B:Int
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View {
        var rootView:View? = null
        if(position == getChoiceTotalSize()){
            rootView = LayoutInflater.from(activity)
                    .inflate(R.layout.aibk_adapter_item_itemanalysis, parent, false)
        }else {
            rootView = LayoutInflater.from(activity)
                    .inflate(R.layout.aibk_adapter_item_child_xzt, parent, false)
        }
        return rootView
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        if(position == getChoiceTotalSize()){
            var childAnalysis = getChildListBean(paperPerAnalysisInfor, index_A, index_B, 0).ChildAnalysis
            CustomTextViewToPicture(activity, holder.convertView.TvItemAnalysis, LancooMethod.getNewItemAnalysis(childAnalysis))
        }else {
            val optionIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, 0).ChildOptionList[position].OptionIndex
            val option = getChildListBean(paperPerAnalysisInfor, index_A, index_B, 0).ChildOptionList[position].Option
            val showType = getChildListBean(paperPerAnalysisInfor, index_A, index_B, 0).ChildOptionList[position].ShowType
            if(showType == 0) {
                holder.convertView.BtnOptionIndex.text = optionIndex
                CustomTextViewToPicture(activity, holder.convertView.TvOptionContent, option)
            }else{
                holder.convertView.BtnOptionIndex.text = option
                CustomTextViewToPicture(activity, holder.convertView.TvOptionContent, "")
            }

            var stuAnswer = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[0].ItemList[0].StuAnswer
            val itemAnswer = getChildListBean(paperPerAnalysisInfor, index_A, index_B, 0).ItemList[0].ItemAnswer
            if (optionIndex == itemAnswer) {
                holder.convertView.BtnOptionIndex.setBackgroundResource(R.mipmap.aibk_icon_choice_green)
                if(itemAnswer == stuAnswer){
                    holder.convertView.BtnDuiGou.visibility = View.VISIBLE
                    holder.convertView.BtnOptionIndex.setTextColor(activity.resources.getColor(R.color.transparent))
                }else {
                    holder.convertView.BtnDuiGou.visibility = View.GONE
                    holder.convertView.BtnOptionIndex.setTextColor(activity.resources.getColor(R.color.lancoooWhite))
                }
            } else {
                holder.convertView.BtnDuiGou.setVisibility(View.GONE)
                if(optionIndex == stuAnswer){
                    holder.convertView.BtnOptionIndex.setBackgroundResource(R.mipmap.aibk_icon_choice_red)
                    holder.convertView.BtnOptionIndex.setTextColor(activity.resources.getColor(R.color.lancoooWhite))
                }else {
                    holder.convertView.BtnOptionIndex.setBackgroundResource(R.mipmap.aibk_icon_choice_white)
                    holder.convertView.BtnOptionIndex.setTextColor(activity.resources.getColor(R.color.textColor))
                }
            }
        }

    }

    private fun getChoiceTotalSize():Int{
        return getChildListBean(paperPerAnalysisInfor, index_A, index_B, 0).ChildOptionList.size
    }

    override fun getItemCount(): Int {
        return getChoiceTotalSize()+1
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

}